package com.teach.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import com.teach.dto.FoodOrderDTO;
import com.teach.dto.HotelOrderDTO;
import com.teach.food.dto.FoodOrderInfoSearch;
import com.teach.food.entity.FoodOrderInfo;

public interface FoodOrderInfoMapper {
    int deleteByPrimaryKey(Integer foodOrderInfoId);

    int insert(FoodOrderInfo record);

    int insertSelective(FoodOrderInfo record);

    FoodOrderInfo selectByPrimaryKey(Integer foodOrderInfoId);

    int updateByPrimaryKeySelective(FoodOrderInfo record);

    int updateByPrimaryKey(FoodOrderInfo record);
    /**
     *  取得某一周(上周 这周)的数据
     * @param str -1 代表的是上周 空值代表的是本周
     * @return  
     */
    @Select("SELECT DATE(food_order_info.food_order_info_time) AS food_order_info_time, SUM(food_order_info.food_order_info_price) AS food_order_info_price FROM food_order_info WHERE food_order_info.food_order_merchant_name=#{name}  and YEARWEEK( date_format(  food_order_info_time,'%Y-%m-%d' ) ) = YEARWEEK( now() ) ${date} GROUP BY DATE(food_order_info.food_order_info_time)")
    List<FoodOrderInfo> statementWeek(@Param("date")String date,@Param("name")String name);
    
    /**
     *  取得某一月(上月 这月 )的数据
     * @param str -1 代表的是上月 空值代表的是本月
     * @return  
     */
    @Select("SELECT DATE(food_order_info.food_order_info_time) AS food_order_info_time, SUM(food_order_info.food_order_info_price) AS food_order_info_price FROM food_order_info  WHERE food_order_info.food_order_merchant_name=#{name}  and DATE_FORMAT( food_order_info_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m' ) ${date} GROUP BY DATE(food_order_info.food_order_info_time)")
    List<FoodOrderInfo> statementMonth(@Param("date")String date,@Param("name")String name);
    
    /**
     * 	带搜索条件的查询
     * @param search 搜索条件
     * @return 查询的结果集
     */
    List<FoodOrderInfo> selectAll(FoodOrderInfoSearch search);
    
    @Select("SELECT * from food_order_info where food_order_info_user_name=#{userName}")
    List<FoodOrderDTO> selectByUserName(String userName);
    @Select("SELECT DATE(food_order_info.food_order_info_time) AS food_order_info_time, SUM(food_order_info.food_order_info_price) AS food_order_info_price FROM food_order_info WHERE food_order_info.food_order_merchant_name=\"湘记厨艺\" and PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( food_order_info.food_order_info_time, '%Y%m' ) ) =1 GROUP BY DATE(food_order_info.food_order_info_time)  ")
    List<FoodOrderInfo> statementLastMonth(@Param("name")String name);
    
}
